﻿using System.Collections.Generic;
using System.Linq;
using UniRx;

/// <summary>
/// 场景内容管理
/// </summary>
public class SceneOrganizer : USaBehaviour
{
    public static SceneOrganizer instance { get; private set; }

    public static PlayerEntity playerInstance { get; set; }


    private List<PlayerSpawner> m_PlayerSpawners = new List<PlayerSpawner>();
    private List<Portal> m_Portals = new List<Portal>();

    private void Awake()
    {
        instance = this;

        m_PlayerSpawners = FindObjectsOfType<PlayerSpawner>().ToList();
        m_Portals = FindObjectsOfType<Portal>().ToList();
    }


    private void OnDestroy()
    {
        instance = null;
    }

    public Portal FindPortal(int portalId)
    {
        return m_Portals.Find(p => p.id == portalId);
    }

    public PlayerSpawner GetPlayerSpawner(int spawnerId = -1)
    {
        if (spawnerId != -1)
            return m_PlayerSpawners.Find(s => s.id == spawnerId);
        if (m_PlayerSpawners.Count > 0)
            return m_PlayerSpawners[0];
        return null;
    }
}